
<template>
    <div class="edu-page-warp">
        <ConditionCard
            shadow="never"
            body-style="padding: 24px 24px 6px 24px;"
            @search="filterTaskSubmit"
            @reset="resetForm('queryForm')"
        >
            <el-form
                ref="queryForm"
                :model="query"
                label-suffix=":"
                label-position="right"
                label-width="65px"
            >
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item label="学院" prop="departmentId" class="no-bottom">
                            <el-select
                                v-model="query.departmentId"
                                placeholder="选择学院"
                                filterable
                                style="width: 100%"
                            >
                                <el-option
                                    v-for="item in options.faculty"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <!-- <el-form-item label="审批状态:" prop="status" class="no-bottom">
                            <el-select
                                v-model="query.status"
                                placeholder="选择审批状态"
                                style="width: 100%"
                            >
                                <el-option
                                    v-for="item in options.status"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item> -->
                        <el-form-item label="起始时间" prop="startTime" class="no-bottom">
                            <el-date-picker
                                v-model="query.startTime"
                                :picker-options="pickerOptions"
                                type="datetime"
                                placeholder="选择开始时间"
                                format="yyyy/MM/dd HH:mm"
                                value-format="timestamp"
                                align="right"
                                style="width: 100%"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="终止时间" prop="endTime" class="no-bottom">
                            <el-date-picker
                                v-model="query.endTime"
                                :picker-options="pickerOptions"
                                type="datetime"
                                placeholder="选择开始时间"
                                format="yyyy/MM/dd HH:mm"
                                value-format="timestamp"
                                align="right"
                                style="width: 100%"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item label="流程类型" prop="wfType">
                            <el-select
                                v-model="query.wfType"
                                placehodler="请选择"
                                style="width: 100%"
                                filterable
                                clearable
                            >
                                <el-option
                                    v-for="item in options.processTypeList"
                                    :key="item.id"
                                    :label="item.typeName"
                                    :value="item.id"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="流程编号" prop="no">
                            <el-input v-model="query.no" placeholder="请输入" clearable></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </ConditionCard>
        <el-card shadow="never" body-style="padding: 24px;" class="card-margin">
            <h1 class="condition-title">审批列表</h1>
            <!-- <div class="div-main clearfix">
                <div class="float-left">
                    <el-input
                        v-model="query.studentId"
                        placeholder="工号 学号或姓名"
                        prefix-icon="el-icon-search"
                        @change="handSearchChang"
                    />
                </div>
                <div class="float-right">
                    <el-button @click="exportDate">导出</el-button>
                </div>
            </div> -->
            <el-table
                :data="taskList"
                tooltip-effect="light"
            >
                <!-- <el-table-column type="selection" width="55" stripe></el-table-column> -->
                <el-table-column prop="applyNo" label="申请编号" min-width="130" show-overflow-tooltip></el-table-column>
                <el-table-column label="流程编号" min-width="120" show-overflow-tooltip>
                    <template slot-scope="scope">{{ scope.row.no }}</template>
                </el-table-column>
                <el-table-column label="申请人" width="80" show-overflow-tooltip>
                    <template slot-scope="scope">{{ scope.row.applicantName }}</template>
                </el-table-column>
                <el-table-column label="申请类型" min-width="120" show-overflow-tooltip>
                    <template slot-scope="scope">{{ scope.row.wfTypeName }}</template>
                </el-table-column>
                <!-- <el-table-column label="申请人编号"><template slot-scope="scope">{{ scope.row.applicantId }}</template></el-table-column> -->
                <el-table-column label="申请时间" width="150" show-overflow-tooltip>
                    <template slot-scope="scope">{{ scope.row.time | formatDate }}</template>
                </el-table-column>
                <el-table-column label="审批状态" width="80">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.status == 'Process'" type="success">进行中</el-tag>
                        <el-tag v-if="scope.row.status == 'End'" type="info">通过</el-tag>
                        <el-tag v-if="scope.row.status == 'Reject'" type="warning">已驳回</el-tag>
                        <el-tag v-if="scope.row.status == 'Recall'" type="warning">撤回</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="下一级审批人" min-width="120" show-overflow-tooltip>
                    <template slot-scope="scope">{{ scope.row.approvorName }}</template>
                </el-table-column>
                <el-table-column label="操作" width="90">
                    <template slot-scope="scope">
                        <el-button
                            v-if="scope.row.status != 'Process'"
                            type="text"
                            size="mini"
                            @click="showRollDetail(scope.row)"
                        >
                            查看明细
                        </el-button>
                        <!-- &&scope.row.wfType!=160 -->
                        <el-button
                            v-if="scope.row.status == 'Process'&&scope.row.wfType!=160||scope.row.wfType==160&&global.isAdmin"
                            type="text"
                            size="mini"
                            @click="showRollDetail(scope.row,'audit')"
                        >
                            审核
                        </el-button>
                        <el-button
                            v-if="scope.row.status == 'Process'&&scope.row.wfType==160&&!global.isAdmin"
                            type="text"
                            size="mini"
                            @click="showRollDetail(scope.row,'onPass')"
                        >
                            通过
                        </el-button>
                        <el-button
                            v-if="scope.row.status == 'Process'&&scope.row.wfType==160&&!global.isAdmin"
                            type="text"
                            size="mini"
                            @click="showRollDetail(scope.row,'onReject')"
                        >
                            驳回
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="edu-pagination">
                <div class="float-right">
                    <el-pagination
                        :current-page="query.pageNum"
                        :page-sizes="[20, 50, 100, 500, 1000]"
                        :page-size="query.pageSize"
                        :total="query.total"
                        layout="total, sizes, prev, pager, next, jumper"
                        style="float: right; margin: 10px 60px 0 0"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                    />
                </div>
            </div>
        </el-card>
      <edu-dialog :title="$t('graduationDesign.batchReject')" width="45%" @close="onRejectClose" :visible="rejectDialogVisible">
        <el-form :model="rejectForm" :rules="rejectRules" ref="rejectForm" label-position="right" label-width="100px" label-suffix="：">
          <el-form-item :label="$t('graduationDesign.reviewOpioion')" prop="content">
            <el-input v-model="rejectForm.content" type="textarea" :rows="4" maxlength="100" class="search-item" show-word-limit :placeholder="$t('graduationDesign.pleaseEnter')"></el-input>
          </el-form-item>
        </el-form>
        <div slot="buttons">
          <el-button @click="onRejectClose">{{$t('graduationDesign.cancel')}}</el-button>
          <el-button type="danger" @click="onRejectSubmit">{{$t('graduationDesign.reject')}}</el-button>
        </div>
      </edu-dialog>
    </div>
</template>
<script>
import { selectTaskList } from 'common/src/api/approval'
import { queryDic } from 'common/src/api/dictionary'
import { getGraduateDegreePage } from 'common/src/api/resource/course'
import filters from 'common/src/filters'
import WorkflowApi from 'common/src/api/workflow'
import API from "common/src/api/underGraduationDesign/reviewSubject";
import mixin from 'common/src/mixins/index';
export default {
    name: 'teacher-roll-check',
    mixins: [mixin],
    filters: {
        formatDate(date) {
            return filters.formatDate(date, 'yyyy/MM/dd hh:mm:ss')
        },
    },
    data() {
        return {
          rejectDialogVisible:false,
          rejectForm: {
            content:''
          },
          api: API,
          rejectRules: {
            content: [
              { required: true, message: this.$t('graduationDesign.pleaseEnter'), trigger: "blur" }
            ]
          },
          rows:{},
            query: {
                total: 0,
                startTime: '',
                endTime: '',
                departmentId: '',
                status: '',
                studentId: '',
                wfType: this.$route.params.id,
                no: '',
                pageNum: 1,
                pageSize: 20,
            },
            options: {
                status: [
                    {
                        value: '',
                        label: '全部',
                    },
                    {
                        value: 'Process',
                        label: '进行中',
                    },
                    {
                        value: 'End',
                        label: '已结束',
                    },
                    {
                        value: 'Reject',
                        label: '已驳回',
                    },
                ],
                faculty: [],
                processTypeList: [],
            },
            pickerOptions: {
                shortcuts: [
                    {
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date())
                        },
                    },
                    {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date()
                            date.setTime(date.getTime() - 3600 * 1000 * 24)
                            picker.$emit('pick', date)
                        },
                    },
                    {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date()
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
                            picker.$emit('pick', date)
                        },
                    },
                ],
            },
            taskList: [],
        }
    },
    created() {
        this.initOptions()
        this.queryProcessTypeList();
    },
    methods: {
        async initPage() {
            let tasks = ''
            try {
                tasks = await selectTaskList(this.query)
                if (tasks.code === 200) {
                    this.query.total = tasks.data.total_
                    this.taskList = tasks.data.list
                }
            } catch (err) {}
        },
        /**
         * 查询流程类型
         */
        async queryProcessTypeList() {
            let { code, data } = await WorkflowApi.selectTemplateType()
            if (code !== 200) return
            this.options.processTypeList = data
        },
        initOptions() {
            const data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['X_YX'],
            }
            queryDic(data).then((res) => {
                if (res.code === 200) {
                    this.fillSelect(res.data)
                    this.filterTaskSubmit()
                }
            })
        },
        getGraduateDegreePage(college) {
            const data = {
                college: college,
                page: false,
            }
            return getGraduateDegreePage(data)
        },
        fillSelect(data) {
            this._fill('faculty', data.X_YX)
        },
        _fill(type, data) {
            for (const key in data) {
                this.options[type].push({
                    value: key,
                    label: data[key],
                })
            }
        },
        async handSearchChang() {},
        handleSizeChange(pageSize) {
            this.query.pageSize = pageSize
            this.query.pageNum = 1
            this.initPage(this.queryItem)
        },
        handleCurrentChange(pageNum) {
            this.query.pageNum = pageNum
            this.initPage(this.queryItem)
        },
        exportDate() {},
        showRollDetail(row,sta) {

            if(row.wfType==135){//经费管理审核
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      pathKey: 'audit'
                  }
              })
            }else if(row.wfType==167){//培养过程综合评价导师审核
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      pathKey: 'audit'
                  }
              })
            }else if(row.wfType==133){//实习基地
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      indexKey: '1'
                  }
              })
            }else if(row.wfType==136){//分散实习申请
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      pathKey: 'auditFculty'
                  }
              })
            }else if(row.wfType==137){//重修申请
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      pathKey: 'auditFculty'
                  }
              })
            }else if(row.wfType==98){//招生计划
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      indexKey: '2',
                      isAudit:true
                  }
              })
            }else if(row.wfType==150||row.wfType==151){//课题申报
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      indexKey: 'REVIEW',
                      currentAction: 'REVIEW_STU',
                  }
              })
            }else if(row.wfType==161){//提交开题报告
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      indexKey: 'REVIEW',
                      actionType:'REVIEW'
                  }
              })
            }else if(row.wfType==162){//提交任务书
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      indexKey: 2,
                      actionType:'REVIEW'
                  }
              })
            }else if(row.wfType==169){//学生中期检查
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      indexKey: 'REVIEW',
                      actionType:'REVIEW'
                  }
              })
            }else if(row.wfType==168){//学生中期检查
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      indexKey: 'REVIEW',
                      actionType:'REVIEW'
                  }
              })
            }else if(row.wfType==141){//课题变更审核
              this.$router.push({
                  path: '/TeacherRollDetail?id=' + row.no,
                  query: {
                      indexKey: '2',
                      actionType:'REVIEW_STU',
                      currentAction:'REVIEW_STU'
                  }
              })
            }else if(row.wfType==160){//学生课题申报
              this.rows=row;
              if(sta=='onPass'){//通过
                  this.$eduConfirm(this.$t('graduationDesign.passConfirmTips'), this.$t('graduationDesign.prompt')).then(() => {
                  const params = {
                    no: row.no,
                    type: "1",
                    // grade: row.content.grade
                  };
                  let reqApi = null;
                  reqApi = this.api.stuApproval(params);
                  reqApi.then(res => {
                    if(res.code==200){
                      this.$message.success('成功');
                    }
                  this.filterTaskSubmit();
                }).catch(() => { });
                }).catch(() => { });
              }if(sta=='audit'){//第二次审核
                this.$router.push({
                    path: '/TeacherRollDetail?id=' + row.no,
                    query: {
                      indexKey: 'REVIEW',
                      actionType:'REVIEW_STU',
                    }
                })
              }if(sta=='onReject'){//驳回
                this.rejectDialogVisible=true;
              }else{
                
              }
            }
            else{
              this.$router.push('/TeacherRollDetail?id=' + row.no)
            }
        },
        resetForm(formName) {
            this.$refs[formName].resetFields()
            this.initPage();
        },
        filterTaskSubmit() {
            this.initPage()
        },
        onRejectClose() {
          this.rejectDialogVisible = false;
        },
        onRejectSubmit(){
            this.$refs.rejectForm.validate(valid => {
              if (valid) {
                let reqApi = null;
                let params = [];
                  params = {
                    no: this.rows.no,
                    type: "2",
                    content: this.rejectForm.content,
                  };
                reqApi = this.api.stuApproval(params);
                reqApi.then(res => {
                if(res.code==200){
                  this.$message.success('成功')
                  this.rejectDialogVisible=false;
                  this.filterTaskSubmit();
                  }
                })
              } else {
                return false;
              }
            });
        }
    },
}
</script>
<style scoped>
.div-main {
    margin-bottom: 16px;
}
</style>
